home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / OS2 / HELLO.ZIP / dos / JCSORT.BAT < prev   
Encoding:
DOS Batch File  |  1996-03-11  |  1.9 KB  |  46 lines

  1. /******************************* REXX *********************************/
  2. /*            REXX subroutine to sort items in the stack.             */
  3. /*  This simple sort algorithm is based on a "3-index sort" I         */
  4. /*  learned way back in school at the Grumman Data Systems            */
  5. /*  Institute.  The table will be sorted in one complete pass.  All   */
  6. /*  items to be sorted should be placed into the REXX stack.  The     */
  7. /*  first item in the stack to be read should contain the number of   */
  8. /*  elements in the stack.  Upon return to the calling routine, all   */
  9. /*  items in the stack will be sorted in ascending sequence.  This    */
  10. /*  code is released to the public domain by the author.  The author  */
  11. /*  may be contacted at 72267.1372@compuserve.com, or jcruz@ibm.net.  */
  12. /*  Enjoy!                                                            */
  13. /**********************************************************************/
  14. /*               Load items in the stack into a table.                */
  15. /**********************************************************************/
  16. Parse Pull table.0
  17. Do x = 1 To table.0
  18.    Parse Pull table.x
  19. End
  20.  
  21. /**********************************************************************/
  22. /*    If there is more than one element in the stack, sort them.      */
  23. /**********************************************************************/
  24. If table.0 > 1 Then
  25.    Do x = 1 To table.0
  26.       y = x
  27.       Do z = (x + 1) To table.0
  28.          If table.y > table.z Then
  29.             y = z
  30.       End
  31.       If x <> y Then
  32.          Do
  33.             Push table.x
  34.             table.x = table.y
  35.             Parse Pull table.y
  36.          End
  37.    End
  38.  
  39. /**********************************************************************/
  40. /*        Dump the sorted elements back on to the stack FIFO          */
  41. /**********************************************************************/
  42. Do x = 0 To table.0
  43.    Queue table.x
  44. End
  45. Return 0
  46.